package org.lc.stk.web.controller.baseInfo;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.lc.stk.model.baseInfo.DepartmentType;
import org.lc.stk.service.baseInfo.DepartmentTypeService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/department-types")
@Tag(name = "部门类型管理")
@RequiredArgsConstructor
public class DepartmentTypeController {
    private final DepartmentTypeService service;

    @GetMapping
    @Operation(summary = "获取所有部门类型")
    public ResponseEntity<List<DepartmentType>> getAll() {
        return ResponseEntity.ok(service.findAll());
    }

    @GetMapping("/{code}")
    @Operation(summary = "根据编码获取部门类型")
    public ResponseEntity<DepartmentType> getByCode(@PathVariable String code) {
        return ResponseEntity.ok(service.findByCode(code));
    }

    @PostMapping
    @Operation(summary = "创建部门类型")
    public ResponseEntity<DepartmentType> create(@RequestBody DepartmentType type) {
        return ResponseEntity.status(HttpStatus.CREATED).body(service.create(type));
    }

    @PutMapping("/{id}")
    @Operation(summary = "更新部门类型")
    public ResponseEntity<DepartmentType> update(@PathVariable Integer id, @RequestBody DepartmentType type) {
        type.setId(id);
        return ResponseEntity.ok(service.update(type));
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除部门类型")
    public ResponseEntity<Void> delete(@PathVariable Integer id) {
        service.delete(id);
        return ResponseEntity.noContent().build();
    }
}